﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using Axis.Dao.Research;
using Axis.Web.Administrator.Global;
using Axis.BusinessObject.Research;
using Axis.Web.Administrator.Views.Project;
using System.Web.Script.Serialization;
using System.Text;
using Axis.Dao.News;
using Axis.BusinessObject.News;
using Axis.BusinessObject.Core;

namespace Axis.Web.Views.TagCloud
{
    public class CCloundTagUI : System.Web.UI.Page
    {
        CNewsDao newsDao = new CNewsDao();
        public string GetListTab()
        {
            var member = new CMemberList();
            if (Session == null) return "aa";
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            IList<CTag> Map = newsDao.GetTags(string.Format("<InputValue UserID=\"{0}\" RowsPerPage='2000' PageIndex='1' />", member.ID.ToString()));
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(Map);
        }
        public string GetListTab(string Context)
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            IList<CTag> Map = newsDao.GetTags(string.Format("<InputValue UserID=\"{0}\" Context=\"{1}\" />", member.ID.ToString(), Context));
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(Map);
        }
        public string GetListNews(string NewsID)
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            IList<CTag> Map = newsDao.GetTags(string.Format("<InputValue UserID=\"{0}\" NewsID=\"{1}\"/>", member.ID.ToString(), NewsID));
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(Map);
        }
        public string GetListProject(string ProjectID)
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            IList<CTag> Map = newsDao.GetTags(string.Format("<InputValue UserID=\"{0}\" ProjectID=\"{1}\"/>", member.ID.ToString(), ProjectID));
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(Map);
        }

        public string GetListNews(string Tags, string PageIndex, string RowsPerPage)
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            IList<CContent> listNewItems = newsDao.GetContent(string.Format("<InputValue MEMBER=\"{0}\" Tags=\"{1}\"/>", member.ID.ToString(), Tags));
            JavaScriptSerializer js = new JavaScriptSerializer();
            string listSerializer = js.Serialize(listNewItems);
            int totalRecords = newsDao.LastOutputValue.TotalRows;
            int totalPages = newsDao.LastOutputValue.TotalPages;
            return string.Format("{{list:{0},total:{1},page:{2}}}", listSerializer, totalRecords, totalPages);
        }
    }
}